<?php

/*
 *  author Ghazy
 */


 class UMS_Admin_User {

     //constants
     const MAIL_EXIST = 1;
     const NAME_EXIST = 2;
     const ADD_SUCCESS = 0;
     const EDIT_SUCCESS = 3;

     //functions
     public function adduser( $mail, $name, $pass, $role, $status, $date)
     {
         $obj = new TblUser();
         $chk_name = TblUser::checkUserExist($name);
         $chk_mail = TblUser::checkMailExist($mail);
       //************make sure that mail and name are unique***********
       if( $chk_name || $chk_mail )
       {
          if( $chk_name )
          {
              return self::NAME_EXIST;
          }
          else
          {
              return self::MAIL_EXIST;
          }
       }
       else
       {
           $obj->adduser($mail, $name, $pass, $role, $status, $date);
           return self::ADD_SUCCESS;
       }

     }
     

     public function editUser($id, $mail, $name, $role, $status, $date)
     {
         //check data (username:unique mail:unique .....
         $chk_name = TblUser::chkNewName($id, $name);
         $chk_mail = TblUser::chkNewMail($id, $mail);
       //************make sure that mail and name are unique***********
       if( $chk_name || $chk_mail )
       {
          if( $chk_name )
          {
              return self::NAME_EXIST;
          }
          else
          {
              return self::MAIL_EXIST;
          }
       }
       else
       {
           TblUser::editUserbyId($id, $mail, $name, $role, $status, $date);
           return self::EDIT_SUCCESS;
       }
     }

     
     public function removeUser ($id)
     {
         //check that id is not root_id or role admin
         TblUser::deleteUser($id);
     }
         
}

